package com.mybatiscore.jiaocheng.d03mybatis查询专项;

import com.mybatiscore.Mapper.StudentMapper;
import com.mybatiscore.Util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;
import java.util.Map;

public class d02返回Map {
    //单个Map
    @Test
    public void oneMap(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        Map<String, Object> stringObjectMap = mapper.selectByIdMap(1L);
        System.out.println(stringObjectMap);
        sqlSession.close();
    }

    //多个Map(List<Map>)
    @Test
    public void AllListMap(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<Map<String, Object>> maps = mapper.selectListMap();
        maps.forEach(map-> System.out.println(map));
        sqlSession.close();
    }

    //Map<String,Map>
    @Test
    public void AllMap(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        Map<Long, Map<String, Object>> longMapMap = mapper.selectMapAll();
        System.out.println(longMapMap);
        sqlSession.close();
    }

}
